clear matrix 
	clear
	set more off
	set seed 123456789
	capture log close
	log using "C:\Users\Patron\OneDrive - UW-Madison\Graduate School\Academics\Fall 2020\PA 888 Social Policy\SP\Analysis Feb 2021\Analysis for 2018\Postpsm\Mortality\Log_mortality_postpsm.log", replace  // created a new log file 
	
	cd "C:\Users\Patron\OneDrive - UW-Madison\Graduate School\Academics\Fall 2020\PA 888 Social Policy\SP\Analysis Feb 2021\Analysis for 2018\Postpsm\Mortality"  // setting the current directory
	clear
	
use "C:\Users\Patron\OneDrive - UW-Madison\Graduate School\Academics\Fall 2020\PA 888 Social Policy\SP\PBS Processed Data\All provinces and regions\1314 and 1819 Combined Feb 2021\postpsm_mortality_vf.dta", replace
	
	
	
	
*************infant mortality****************	
	
	keep if birth_year >= 2011
	keep if birth_year <= 2018
	
	keep if population_halves == 1
	
generate byte cond1 = survey_quarter == 1 | survey_quarter == 3 | survey_quarter == 4

drop if birth_year >= 2018 & birth_month >= 4

drop if birth_year >= 2018 & birth_month >= 0 & cond1

generate byte cond2 = survey_quarter == 3 | survey_quarter == 4

drop if birth_year == 2017 & birth_month >= 10 & cond2

drop if birth_year == 2017 & birth_month >= 7 & survey_quarter == 3

tab treat
	
*****data for common trend assumption graph	*******

tabstat infant_mortality if treat == 1, by(birth_year)
tabstat infant_mortality if treat == 0, by(birth_year)


tab birth_year

*******testing common trend assumption via regression***************

gen time_trend = birth_year - 2011
gen inter_trend = time_trend*treat

local outputfile1 common_trend_reg.xls
set seed 12345678

bootstrap, reps(200): reg infant_mortality treat time_trend inter_trend birth_sequence hh_head_gender head_employment_status head_highest_grade hh_annual_income hh_annual_transfers hh_annual_exp_food_nondurables hh_annual_exp_durables hh_size dwelling_type occupancy_status distance_to_drinking_water drinking_water_soruce drainage_sewerage_connection garbage_hh garbage_neighborhood if time == 0, cluster(district) robust
outreg2 using `outputfile1'


//creating dummy variable for each year for year fixed effects
 xi i.birth_year


*********DiD Estimations Tables for infant mortality**************

local outputfile_dd_infant dd_infant_table.xls
set seed 123456789
bootstrap, reps(200): reg infant_mortality time treat did_estimator, cluster(district) robust
outreg2 using `outputfile_dd_infant'

set seed 123456789
bootstrap, reps(200): reg infant_mortality time treat did_estimator _Ibirth_yea*, cluster(district) robust
outreg2 using `outputfile_dd_infant'

set seed 123456789
bootstrap, reps(200): reg infant_mortality time treat did_estimator birth_sequence hh_head_gender head_employment_status head_highest_grade hh_annual_income hh_annual_transfers hh_annual_exp_food_nondurables hh_annual_exp_durables hh_size dwelling_type occupancy_status distance_to_drinking_water drainage_sewerage_connection garbage_hh garbage_neighborhood drinking_water_soruce _Ibirth_yea*, cluster(district) robust
outreg2 using `outputfile_dd_infant'





****************neo natal mortality**************

clear
clear matrix
use "C:\Users\Patron\OneDrive - UW-Madison\Graduate School\Academics\Fall 2020\PA 888 Social Policy\SP\PBS Processed Data\All provinces and regions\1314 and 1819 Combined Feb 2021\postpsm_mortality_vf.dta", replace

keep if birth_year >= 2011
keep if birth_year <= 2018
keep if population_halves == 1

drop if birth_year == 2018 & birth_month >= 7 & survey_quarter == 3

drop if birth_year == 2018 & birth_month >= 10 & survey_quarter == 4 

drop if birth_year >= 2019 & birth_month >= 0 & survey_quarter == 1

drop if birth_year >= 2019 & birth_month >= 4 & survey_quarter == 2 



************common trend graph****************

tabstat neonatal_mortality if treat == 1, by(birth_year)
tabstat neonatal_mortality if treat == 0, by(birth_year)


*******testing common trend assumption via regression***************

gen time_trend = birth_year - 2011
gen inter_trend = time_trend*treat

local outputfile1 common_trend_reg.xls
set seed 12345678

bootstrap, reps(200): reg neonatal_mortality treat time_trend inter_trend birth_sequence hh_head_gender head_employment_status head_highest_grade hh_annual_income hh_annual_transfers hh_annual_exp_food_nondurables hh_annual_exp_durables hh_size dwelling_type occupancy_status distance_to_drinking_water drinking_water_soruce drainage_sewerage_connection garbage_hh garbage_neighborhood if time == 0, cluster(district) robust
outreg2 using `outputfile1'



//creating dummy variable for each year for year fixed effects
 xi i.birth_year

*********DiD Estimations Tables for neonatal mortality**************

local outputfile_dd_neonatal dd_neonatal_table1.xls

set seed 123456789
bootstrap, reps(200): reg neonatal_mortality time treat did_estimator, cluster(district) robust
outreg2 using `outputfile_dd_neonatal'

set seed 123456789
bootstrap, reps(200): reg neonatal_mortality time treat did_estimator _Ibirth_yea*, cluster(district) robust
outreg2 using `outputfile_dd_neonatal'

set seed 123456789
bootstrap, reps(200): reg neonatal_mortality time treat did_estimator birth_sequence hh_head_gender head_employment_status head_highest_grade hh_annual_income hh_annual_transfers hh_annual_exp_food_nondurables hh_annual_exp_durables hh_size dwelling_type occupancy_status distance_to_drinking_water drainage_sewerage_connection garbage_hh garbage_neighborhood drinking_water_soruce _Ibirth_yea*, cluster(district) robust
outreg2 using `outputfile_dd_neonatal'


**************************************************

log close



